package ca.shojaei.mini_sat;

import java.util.*;


public class Or extends Clause  {

	public Or() {
		super();
		this.unary = false;
		this.evaluable = false;
	}
	Clause p;
	Clause q;
	String symbol = "|";
	public Or(Clause p, Clause q, String symbol) {
		super();
		this.p = p;
		this.q = q;
		this.symbol = symbol;
		this.unary = false;
	}
	
	public Clause getLeft(){
		return getP();
	}
	public void setLeft(Clause c){
		setP(c);
	}
	
	public Clause getRight(){
		return getQ();
	}
	public void setRight( Clause c){
		setQ(c);
	}
	
	public Clause getP() {
		return p;
	}
	public void setP(Clause p) {
		this.p = p;
	}
	public Clause getQ() {
		return q;
	}
	public void setQ(Clause q) {
		this.q = q;
	}
	public String getSymbol() {
		if(this.negated){
			String str = "!".concat(this.symbol);
			return str;
		}
		return symbol;
	}
	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}
	
	public boolean evaluate(Model m)
	{
		boolean out;
		out = p.evaluate(m) || q.evaluate(m);
		
		if(negated)
			out = !out;
		
		return out;
	}
	
	public Vector<int[]> getDIMACS(Model mod)
	{
		Vector<int[]> v = new Vector<int[]>();
		Vector<int[]> pv = p.getDIMACS(mod);
		Vector<int[]> qv = q.getDIMACS(mod);
		
		for(int i = 0; i < pv.size() ; i++){
			for(int j = 0; j < qv.size(); j++)
			{
				int[] temp = new int[pv.get(i).length + qv.get(j).length];
				int counter = 0;
				for(int m = 0 ; m < pv.get(i).length ; m++)
				{
					assert(counter < temp.length);
					temp[counter] = pv.get(i)[m];
					counter++;
					
				}
				for(int m = 0 ; m < qv.get(j).length ; m++)
				{
					assert(counter < temp.length);
					temp[counter] = qv.get(j)[m];
					counter++;
				}
				v.add(temp);
			}
		}
		
		return v;
		
		
	}
}
